import request from '@/plugins/axios';

const baseURL = import.meta.env.VITE_APP_SERVER_API;
const workspace = import.meta.env.VITE_APP_SERVER_WORKSPACE_API;

// 查询 地块 对应的数据
export function api_getLandExtendInfo(params) {
    return request({
        url: '/landArchive/getlandArchive',
        method: 'GET',
        params
    })
}

// 获取行政区划图层
export function api_getDistrictServer(filter) {
    let r = {
        url: `${baseURL}/geoserver/${workspace}/wfs`,
        method: "GET",
        params: {
            version: "1.1.0",
            request: "GetFeature",
            typeName: `${workspace}:district_full`,
            outputFormat: "application/json",
            service: "WFS",
        },
    };

    if (filter !== "") {
        r.params.cql_filter = filter;
    }

    return request(r).then((res) => {
        return res;
    }).catch((error) => {
        console.error(error);
        return [];
    });
}


// 条件检索地块分页接口
export function api_getLandsByCondition(params) {
    return request({
        url: "/parcel/base/parcel/page",
        method: "GET",
        params,
    })
        .then((res) => {
            return res.data;
        })
        .catch((error) => {
            console.error(error);
            return {};
        });
}

// 地块检索
export function api_getBussinessLand(bsm, gtdcbsm) {
    let r = {
        url: `${baseURL}/geoserver/${workspace}/wfs`,
        method: "GET",
        params: {
            version: "1.1.0",
            request: "GetFeature",
            typeName: `${workspace}:ready,${workspace}:three_build`,
            outputFormat: "application/json",
            service: "WFS",
        },
    };
    if (bsm !== "") {
        r.params.cql_filter = `bsm = ${bsm} OR old_bsm = ${gtdcbsm}`;
    }
    return request(r)
        .then((res) => {
            return res.features ? res.features : [];
        })
        .catch((error) => {
            console.error(error);
            return [];
        });
}